﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Brain.Rendering
{
    public class Quad
    {
        public VertexBuffer VertexBuffer;
        public IndexBuffer IndexBuffer;

        public Quad()
        {
            VertexPositionTexture[] Vertices = new VertexPositionTexture[]
            {
                new VertexPositionTexture(
                                new Vector3(1,-1,0),
                                new Vector2(1,1)),
                new VertexPositionTexture(
                                new Vector3(-1,-1,0),
                                new Vector2(0,1)),
                new VertexPositionTexture(
                                new Vector3(-1,1,0),
                                new Vector2(0,0)),
                new VertexPositionTexture(
                                new Vector3(1,1,0),
                                new Vector2(1,0))
            };
            short[] Indices = new short[] { 0, 1, 2, 2, 3, 0 };

            VertexBuffer = new VertexBuffer(Engine.Instance.GraphicsDevice, typeof(VertexPositionTexture), Vertices.Length,
                BufferUsage.None);
            VertexBuffer.SetData(Vertices);

            IndexBuffer = new IndexBuffer(Engine.Instance.GraphicsDevice, IndexElementSize.SixteenBits, Indices.Length,
                BufferUsage.None);
            IndexBuffer.SetData(Indices);
        }

        public virtual void DrawQuad()
        {
            GraphicsDevice device = Engine.Instance.GraphicsDevice;
            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, VertexBuffer.VertexCount,
                0, IndexBuffer.IndexCount / 3);
        }
    }
}
